<template>
	<view id="password">
		<view class="dataBox">
			<text class="text">手机号码 ：</text>
			<input type="number" class="data" v-model="mobile" placeholder="请输入手机号"></input>
		</view>
		<view class="dataBox">
			<text class="text">验证码 ：</text>
			<input class="data" v-model="verCode" placeholder="请输入验证码"></input>
			<text class="btn" @click="handVerCode">{{getCode}}</text>
		</view>
		<view class="dataBox">
			<text class="text">新密码 ：</text>
			<input type="password" class="data" v-model="password" placeholder="请输入新密码"></input>
		</view>
		<view class="dataBox">
			<text class="text">确认新密码 ：</text>
			<input type="password" class="data" v-model="rePassword" placeholder="请输入新密码"></input>
		</view>
		
		<view class="btn-div">
			<button type="primary" class="primary" @tap="submit">确认修改</button>
		</view>
	</view>
</template>

<script>
	
	export default {
		data() {
			return {
				getCode:'获取验证码',
				mobile:uni.getStorageSync("userInfo").mobile,
				verCode:'',
				password:'',
				rePassword:'',
				timerFlag:false,
				imgSrcFlag:false
			}
		},
		onLoad(){
		},
		methods: {
			//发送验证码
			handVerCode(){
				if (!/[0-9]{11}/.test(this.mobile)) {
					uni.showToast({
						icon: 'none',
						title: '请输入正确的手机号'
					})
					return
				}
				if (this.timerFlag === false) {
					this.httpClient.post('agents/app/agent/index/sendcode', {
						mobile:this.mobile
					}).then(res=>{
						if(res.code==200){
							this.timerFlag = !this.timerFlag
							uni.showToast({
								icon: 'none',
								title: res.msg
							})
							this.countDown(60)
						}
					})
				}
			},
			//倒计时
			countDown (time) {
				let count = time
				setTimeout(() => {
					count--
					if (time <= 0) {
						this.getCode = '获取验证码'
						this.timerFlag = false
					} else if (count !== time) {
						this.getCode = '重新获取' + count
						this.countDown(count)
					}
				}, 1000)
			},
			//提交修改
			submit: function() {
				let that = this;
				this.httpClient.post('agents/app/agent/index/editPassword', {
					vercode:this.verCode,
					rePassword: this.rePassword,
					password: this.password
				}).then(res => {
					if (res.code == 200) {
						uni.showToast({
							icon: 'none',
							title: res.msg
						});
						setTimeout(function() {
							uni.removeStorageSync("access_token")
							uni.reLaunch({
								url: '/pages/common/login'
							});
						}, 1000)
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	#password{
		.dataBox {
			background:#FFF;
			padding:20rpx;
			align-items: center;
			justify-content: center;
			display:flex;
			border-bottom:1rpx solid #f7f7f7;
			.text{
				width:250rpx;text-align: right;color:#888;
			}
			.data{
				flex:1
			}
			.btn{
				width:150rpx;font-size:24rpx;padding:10rpx;margin:0;
			}
		}
		.btn-div{
			margin:20rpx 30rpx;
		}
		.warning{
			padding:20rpx 40rpx;color:#888;font-size:28rpx;
			i{
				margin-right:10rpx;font-size:28rpx;
			}
		}
	}
	
</style>
